{extend name="template/base_default"}
{block name="header"}
<link rel="stylesheet" href="__CSS__/common.css">

<link rel="stylesheet" href="__CSS__/index.css">
<link rel="stylesheet" href="__CSS__/weui.min.css">
<link rel="stylesheet" href="__CSS__/weuix.min.css">
<link rel="stylesheet" href="__CSS__/jquery-weui.css">
<style>
    .login-form{
        background: white;
    }
    body{
        background-image:url("__IMG__/bj.png");
        background-repeat:repeat-y;
        background-size:cover;
        text-align: center;
    }
    .main-wrap{
        padding-bottom: 30px;
    }
    .code-btn{
        width:26%;
        font-size: 12px;
    }
</style>
{/block}
{block name="body"}
<div class="main-wrap">
<div id="personalHeader" onclick="">
    <ul>
        <li><div class="c-logo" ><img class="m-avatar"  src="__IMG__/che.png" /></div></li>
    </ul>
</div>
<form action="{:url('login/register')}" method="post" style="width:80%;margin: auto">

        <div class="form-input">
            <input class="weui-input" type="tel" id="phone" placeholder="手机号">
        </div>
    <div class="form-input">
        <input class="weui-input" type="text" name="t_code" id ='t_code' style="float: left;width: 50%" placeholder="请输入验证码">
        <img style="width:40%;margin-top: 1em" onclick="refresh_verify();" src="{:url('verify/random',array('r'=>time()))}" class="verifyimg" id="verifyimg" alt="验证码" title="点击换一张"/>

    </div>

    <div class="form-input">

            <input class="weui-input" type="text" name="code" id ='code' style="float: left;width: 70%" placeholder="请输入短信验证码">
        <button id="getcode" class="code-btn" type="button" style="float: left;margin-top: 17px">获取验证码</button>

    </div>

        <div class="form-input">
            <input class="weui-input" type="password" id="password" placeholder="请输入密码">
        </div>
        <div class="form-input">
            <input class="weui-input" type="password" id="repassword"  placeholder="确认密码">
        </div>
    <div class="form-input">
        <input class="weui-input" type="text" name="invite_code" id="invite_code" value="{$invite_code|default='' }" placeholder="邀请码">
    </div>

    <div class="form-input">
        <button id="submit" class="login-btn" type="button">确定</button>
    </div>
</form>
</div>
{/block}
{block name="footer"}
<script type="text/javascript" src="__JS__/public.js"></script>
<script>

    function refresh_verify(){
        $('#verifyimg').attr('src',getBaseUrl()+'web.php/verify/random' + '/r/' + (new Date()).getTime() / 1000);
    }
    $('#submit').click(function () {
        var $phone = $('#phone');
        var $code = $('#code');
        if(!$phone.val()||isNaN($phone.val())||$phone.val().length != 11){
            $.toast("输入11位手机号",'cancel');
        }else if($('#password').val().length<6){
            $.toast("密码长度不可以小于6位",'cancel');
        }else if($('#password').val()!=$('#repassword').val()){
            $.toast("两次密码不一致",'cancel');
        }else{
            var body  ={

                mobile:$phone.val(),
                password:$('#password').val(),
                invite_code:$('#invite_code').val(),
                code:$code.val()
            };
            var $this = $(this);
            $this.addClass('weui-btn_disabled').attr('disabled','disabled');
            ajax_post(getBaseUrl()+'web.php/login/register',jQuery.param(body),{
                success:function(data){
                    $.toast("注册成功",'success');
                    $this.removeClass('weui-btn_disabled').removeAttr("disabled");
                    setTimeout(
                            function(){
                                window.location.href=getBaseUrl()+'web.php/index/index.html';
                            }
                            ,1500);
                },
                error:function(data){
                    $.toptip(data.msg, 'error');
                    $this.removeClass('weui-btn_disabled').removeAttr("disabled");
                }
            })
        }

    });

    var wait=60;
    function time(o) {
        if (wait == 0) {
            o.removeAttribute("disabled");
            o.innerHTML="获取验证码";
            wait = 60;
        } else {
            o.setAttribute("disabled", true);
            o.innerHTML="重新发送(" + wait + ")";
            wait--;
            setTimeout(function() {
                        time(o)
                    },
                    1000)
        }
    }
    $('#getcode').click(function(){

        var $phone=$('#phone');
        if(!$phone.val()||isNaN($phone.val())||$phone.val().length != 11){
          $.toast("输入11位手机号",'cancel');
            return;
        }

        time(this);

        var body  ={
             code:$('#t_code').val(),
            mobile:$phone.val()

        };
        var $this = $(this);
        ajax_post(getBaseUrl()+'web.php/login/getcode',jQuery.param(body),{
            success:function(data){
                $.toptip('获取成功', 'success');
                $this.removeClass('weui-btn_disabled').removeAttr("disabled");
            },
            error:function(data){
                $.toptip(data.data, 'error');
                $this.removeClass('weui-btn_disabled').removeAttr("disabled");
            }
        });
    });

</script>
{/block}